function Get-CentralCompanies {
    [CmdletBinding()]
    [OutputType([string[]])]
    param (
        [Parameter(Mandatory = $true)][LSCentralParameters]$LSCentral,
        [Parameter(Mandatory = $true)][string][ValidateScript({ Test-Path $_ -PathType "Container" })]$ProjectFolder,
        [Parameter(Mandatory = $false)][bool]$ConfirmAll = $false
    )
    # TODO: Split this function into smaller functions.
    <#
        Check the LSCentral parameter object.
    #>

    # Ask user to confirm the companies stored in the $LSCentral object.
    if (Confirm-Companies -Companies $LSCentral.Companies) { return $LSCentral.Companies }

    <#
        Check the Companies.txt file.
    #>

    # Get Companies.txt filepath.
    $CompaniesFile = Join-Path $ProjectFolder -ChildPath "Companies.txt"

    # Ask user about the companies in the existing Companies.txt file.
    if (Test-Path -Path $CompaniesFile -PathType 'Leaf') {
        
        # Read companies from file.
        $CompaniesFromFile = Read-Companies -FilePath $CompaniesFile
        
        # Ask user to confirm companies.
        if (Confirm-Companies -Companies $CompaniesFromFile) { return $CompaniesFromFile }
    }

    <#
        Check the LS Central database.
    #>

    # Get companies from LS Central database.
    $CompaniesFromLSCentral = $()
    if (!($LSCentral.Server.ConfirmedButNotConnectable) -and $LSCentral.HasQueriableParams()) { # TODO: Make sure HasQueriableParams works!
        $CompaniesFromLSCentral = Get-CentralCompaniesFromDB -LSCentral $Parameters.LSCentral
    }

    # Create company file.
    Write-Companies -Companies $CompaniesFromLSCentral -FilePath $CompaniesFile

    # Open the file.
    Invoke-Item -Path $CompaniesFile

    # Ask user to add companies to the file.
    Write-Host # Newline.
    Write-Host "A 'Companies' file has been created at '$CompaniesFile'."
    Write-Host "Please make sure that the file only includes the names of the companies you want to include in LS Insight."
    Write-Host "Each name must be in a separate line in the file and be exactly the same as in the Companies table in LS Central."


    # Read companies from file when user is ready.
    do {
        $CompaniesConfirmed = $null
        Read-Host -Prompt "Press enter when you have reviewed and/or edited the file" | Out-Null
        # Read companies.
        $CompaniesFromFile = Read-Companies -FilePath $CompaniesFile

        if ($CompaniesFromFile.Count -eq 0) {
            # File is empty.
            Write-Host # Newline.
            Write-Warning "No companies were found in the companies file."
        } else {
            # Ask user to confirm company list.
            $CompaniesConfirmed = Confirm-Companies -Companies $CompaniesFromFile
        }
    } while (!$CompaniesConfirmed)

    return $CompaniesFromFile
}